'use strict';

let
    Koa = require('koa'),
    app = new Koa(),
    { Sequelize, DataTypes } = require('sequelize'),
    port = 8888;

//连接数据库
const sequelize = new Sequelize('wechat', 'postgres', 'cultural0725.', {
    host: 'blackdragonlee',
    dialect: 'postgres'
});

// let User = sequelize.define('User', {
//     firstName: {
//         type: Sequelize.DataTypes.STRING,
//         allowNull: false
//     },
//     lastname: {
//         type: Sequelize.DataTypes.STRING
//     }
// });

let User = sequelize.define('user', {
    ID: {
        type: DataTypes.BIGINT,
        primaryKey: true,
        autoIncrement: true
    },
    name: {
        type: DataTypes.STRING(10),
        defaultValue: 'Black'
    },
    age: {
        type: DataTypes.INTEGER
    }
});

(async () => {
    await sequelize.sync({force:true});
    User.create({name:"Blues"})
    console.log("创建成功了！");
})();






// (async ()=>{
//     //若表存在此表则删除表重新创表
//     await sequelize.sync({force:true})
//     let noval = Noval.create({
//         fromUserId:1,
//         tofgrId:2,
//         content:'创建了没？？？'
//     })
// })()


app.listen(port, () => {
    console.log(`http://localhost:${port}`);
})


